﻿using System;
using RAP.Framework.Libary.DomTemplateBuilder.Attributes;
using RAP.Framework.Libary.DomTemplateBuilder.Handler.SwitchCase;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.DomTemplateBuilder.Element.Switch
{
	/// <summary>
	/// Switch Case Element
	/// </summary>
	[TagHandler( typeof( CaseHandler ) )]
    public class Case : SwitchElementBase
    {
		public new Switch Parent
		{
			get
			{
				return base.Parent as Switch;
			}
			set
			{
				base.Parent = value;
			}
		}
				
		public override string Property
		{
			get
			{
				if ( _property.IsNullOrEmpty ( ) )
				{
					_property = this.ToString ( "Property", this.Parent.Property );
				}
				return _property;
			}
		}

		public override string CompareValue
		{
			get
			{
				if ( _compareValue.IsNullOrEmpty ( ) )
				{
					_compareValue = this.ToString ( "CompareValue", this.Parent.CompareValue );
				}
				return _compareValue;
			}
		}

		public override string CompareProperty
		{
			get
			{
				if ( _compareProperty.IsNullOrEmpty ( ) )
				{
					_compareProperty = this.ToString ( "CompareProperty", this.Parent.CompareProperty );
				}
				return _compareProperty;
			}
		}

		public override PropertyValueStyles ValueStyle
		{
			get
			{
				PropertyValueStyles styles = base.ValueStyle;
				_valueStyle = ( styles != PropertyValueStyles.NotSet ? styles : this.Parent.ValueStyle );
				return _valueStyle.Value;
			}
		}

		public override TypeCode ValueType
		{
			get
			{
				TypeCode typeCode = base.ValueType;
				typeCode = ( typeCode != TypeCode.Empty ? typeCode : this.Parent.ValueType );
				return typeCode;
			}
		}

        /// <summary>
        /// IsEquare、IsNotEquare、IsLessThan、IsNotLessThan…
        /// </summary>
        public override string ConditionHandlerName
        {
            get
            {
				return this.ToString ( "ConditionType", this.Parent.ConditionHandlerName );
            }
            set
            {
                this[ "ConditionType" ] = value;
                _conditionHandlerType = null;
                _conditionHandler = null;
            }
        }
    }
}
